from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt

class TartBarJobBox(QtGui.QWidget):
        def __init__(self, *args, **kw):
		QtGui.QWidget.__init__(self, *args, **kw)
		self.setGeometry(0, 0, 90, 40)
#
#		background graphic
#
		bg = QtGui.QLabel(self)
		bg.setGeometry(0, 0, 90, 40)
		path = "resources/tart_bar_job_box.png"
		bg.setPixmap(QtGui.QPixmap(path))

		text = QtGui.QLabel(self)
		text.setGeometry(9, 6, 75, 27)
		font = QtGui.QFont("Times New Roman", 14)
		text.setFont(font)
		text.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter )
		self.text = text
		self.reset()

		self.dark = QtGui.QLabel(self)
		self.dark.setGeometry(4, 3, 84, 33)
		path = "resources/menu_dark.png"
		self.dark.setPixmap(QtGui.QPixmap(path))
		self.dark.hide()
#
#		these are so whoever gets the job menu signal
#		can tell what which of the four it was
#
#		they'll need setting by the caller
#
		self.period_name = None
		self.period_index = -1

	def reset(self):
		self.text.setText("-------------");

	def set_text(self, s):
		self.text.setText(s)
#
#		we need to update the girl. Doing it here feels
#		like a hack, but I'm not sure how best to do it otherwise
#
		bar = self.parentWidget()
		girl = bar.girl
#
#		we can get called before there is a girl to update
#
		if girl == None:
			return
		girl.jobs[self.period_index] = s

	def is_blanked(self):
		return self.dark.isVisible()

	def blanked(self, flag):
		self.dark.setVisible(flag)

	def toggle_blank(self):
		flag = not self.is_blanked()
		self.dark.setVisible(flag)
		return flag

	job_menu = QtCore.pyqtSignal(object)
	def mousePressEvent(self, sender):
		#self.debug_trace()
		self.job_menu.emit(self)
		

	def debug_trace(self):
		'''Set a tracepoint in the Python debugger that works with Qt'''
		from PyQt4.QtCore import pyqtRemoveInputHook
		from pdb import set_trace
		pyqtRemoveInputHook()
		set_trace()

if __name__ == "__main__":
	import sys

	def menu_called(box):
		print "job box clicked for {}:{} {}".format(
			box.period_index,
			box.period_name,
			box.text.text()
		)
		box.blanked(not box.is_blanked())

	app = QtGui.QApplication(sys.argv)

	top = QtGui.QLabel()
	top.setGeometry(0, 0, 300, 400)
	path = "resources/wood.jpg"
	top.setPixmap(QtGui.QPixmap(path))

	yoff = 20
	wid = TartBarJobBox(top)
	wid.period_name = "morning"
	wid.period_index = 0
	wid.move(20,yoff)
	wid.job_menu.connect(menu_called)

	wid = TartBarJobBox(top)
	wid.set_text("Cleaning")
	wid.period_name = "afternoon"
	wid.period_index = 1
	wid.move(140,yoff)
	wid.job_menu.connect(menu_called)

	yoff += 60
	wid = TartBarJobBox(top)
	wid.set_text("Whoring")
	wid.period_name = "evening"
	wid.period_index = 2
	wid.move(20,yoff)
	wid.job_menu.connect(menu_called)

	wid = TartBarJobBox(top)
	wid.set_text("Streets")
	wid.move(140,yoff)

	yoff += 60
	wid = TartBarJobBox(top)
	wid.set_text("Assistant")
	wid.move(20,yoff)

	wid = TartBarJobBox(top)
	wid.set_text("Follow")
	wid.move(140,yoff)

	yoff += 60
	wid = TartBarJobBox(top)
	wid.set_text("Rest")
	wid.move(20,yoff)

	wid = TartBarJobBox(top)
	wid.set_text("Sleep")
	wid.move(140,yoff)

	yoff += 60
	wid = TartBarJobBox(top)
	wid.set_text("Cabaret")
	wid.move(20,yoff)

	wid = TartBarJobBox(top)
	wid.set_text("Bestiary")
	wid.move(140,yoff)

	yoff += 60
	wid = TartBarJobBox(top)
	wid.set_text("Mission")
	wid.move(20,yoff)

	wid = TartBarJobBox(top)
	wid.set_text("Training")
	wid.move(140,yoff)



	top.show()
	sys.exit(app.exec_())

